##!/bin/bash

function usage(){
	echo -e "\tFirst arg : Target's IP"
	echo -e "\tSecond arg : Starting port"
	echo -e "\tThird arg : ending port"
}

if [ $# -ne 3 ] || [ $1 = '-h' ]
then
	usage
	exit
fi

regex='[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
if [[ "$1" =~ $regex ]]
then
	echo "$1"
	echo $regex
	#if grep $regex "$1"; then
	echo "success identification"
	exit
fi

HOST=$1

for((port=$2;port<=$3;++port));
do
	echo -en "$port ";
	if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null; then 
		echo -en "\n\nport $port/tcp is open\n\n";
	fi;
done
